package com.common;


import java.security.MessageDigest;

/**
 * @author james.qin
 * 
 */
public class MD5 {
	public static String getHexMD5Str(String strIn) throws Exception {
		if(strIn == null || "".equals(strIn.trim())){
			  return "";
		}
		return getHexMD5Str(strIn.getBytes());
	}

	public static String getHexMD5Str(byte[] arrIn) throws Exception {
		MessageDigest md = MessageDigest.getInstance("MD5");
		byte[] arrB = md.digest(arrIn);
		StringBuffer sb = new StringBuffer(32);
		for (int i = 0; i < arrB.length; i++) {
			int intTmp = arrB[i];
			while (intTmp < 0) {
				intTmp = intTmp + 256;
			}
			if (intTmp < 16) {
				sb.append('0');
			}
			sb.append(Integer.toString(intTmp, 16));
		}
		return sb.toString().toUpperCase();
	}

	public static void main(String[] args) {
		try {
		    String strTest = "kvonhqif";
			System.out.println(MD5.getHexMD5Str(strTest)); 
			strTest = "8DDCFF3A80F4189CA1C9D4D902C3C909";
			System.out.println(MD5.getHexMD5Str(strTest));           
		} catch (Exception ex) {
		    ex.printStackTrace();
		}

	}

}

